//
//  FQDFeedCacheManager.m
//  FakeQDaily
//
//  Created by mewxiv on 8/18/16.
//  Copyright © 2016 Xensius. All rights reserved.
//

#import "FQDFeedCacheManager.h"
#import "FQDFeedCacheItem.h"

static NSDictionary * FeedCacheTableMap;

@interface FQDFeedCacheManager ()

@property (nonatomic, strong) NSMutableDictionary *cacheDict;

@end

@implementation FQDFeedCacheManager

+ (instancetype)sharedManager
{
    static FQDFeedCacheManager *manager;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        manager = [[self class] new];
    });
    return manager;
}

- (instancetype)init
{
    self = [super init];
    if (self) {
        _cacheDict = [NSMutableDictionary dictionary];
    }
    return self;
}

+ (FQDFeedCacheItem *)cacheForIdentifier:(NSString *)cacheId
{
    FQDFeedCacheManager *manager = [self sharedManager];
    FQDFeedCacheItem *cache = [manager.cacheDict objectForKey:cacheId];
    if (cache == nil) {
        cache = [FQDFeedCacheItem cacheWithIdentifier:cacheId];
        [manager.cacheDict setObject:cache forKey:cacheId];
    }
    return cache;
}

@end
